﻿using TjZheng.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using TjZheng.Framework;

namespace TjZheng.EasyUI
{
    public static partial class QueryExtension
    {
        public static MvcHtmlString QueryComboBox(this HtmlHelper htmlHelper, string title, string name, QueryMethod objQueryMethod, QueryDataType objQueryDataType, string remoteUrl, object htmlAttributes = null, SelectListItem optionLabel = null)
        {
            if (optionLabel == null)
            {
                optionLabel = new SelectListItem { Text = "==全部==" };
            }
            QueryDropDownList objQueryDropDownList = new QueryDropDownList(name, QueryComboType.ComboBox, new List<SelectListItem> { optionLabel })
            {
                QueryTitle = title,
                QueryMethod = objQueryMethod,
                QueryDataType = objQueryDataType,
                HtmlAttributes = htmlAttributes.CreateValueDictionary()
            };
            var objQueryComboBox = htmlHelper.CreateQueryInfo(objQueryDropDownList);
            if (remoteUrl.IsNull())
            {
                return objQueryComboBox;
            }

            StringBuilder objStringBuilder = new StringBuilder(objQueryComboBox.ToHtmlString());
            objStringBuilder.AppendFormat("<script id=\"{0}_script\" type=\"text/javascript\">LoadDropDownList(\"{1}\",\"{2}\",\"{3}\");</script>", objQueryDropDownList.Id, objQueryDropDownList.Id.FormatSelf("#{0}"), "", remoteUrl);
            return MvcHtmlString.Create(objStringBuilder.ToString());
        }
        public static MvcHtmlString QueryComboBox(this HtmlHelper htmlHelper, string title, string name, string remoteUrl, object htmlAttributes = null, SelectListItem optionLabel = null)
        {
            return htmlHelper.QueryComboBox(title, name, QueryMethod.Equal, QueryDataType.Int, remoteUrl, htmlAttributes, optionLabel);
        }
    }
}
